import Vue from 'vue'
import Router from 'vue-router'
import routes from './routers'
import config from '../config'

Vue.use(Router)
const router = new Router({
  routes,
  mode: 'hash'
})

router.beforeEach((to, from, next) => {
  if (to.name === 'main') {
    next({
      name: config.homeName // 跳转到登录页
    })
  }
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

router.afterEach(to => {
  window.scrollTo(0, 0)
})

export default router
